<template>
  <div>
          <label v-if="type === 'user' || type === 'role' || type === 'post' || type === 'company' || type === 'depart'">
             {{label}}
          </label>
          <label  v-if="type === 'applyUserId'">发起人 </label>
          <label  v-if="type === 'previousExecutor'">上一步执行人 </label>
          <label  v-if="type === 'currentUserId'">当前登录用户 </label>
          <label  v-if="type === 'sql'">{{value}} </label>
          <label  v-if="type === 'custom'">{{value}} </label>
  </div>
</template>
<script>
import  {getUserTypeLabel, getRoleLabel, getPostLabel, getUserLabel, getDepartLabel} from './UserUtils'
export default {
  props: {
    value: {
      type: String,
      default: ''
    },
    type: {
      type: String,
      default: ''
    }
  },
  data () {
    return {
      label: ''
    }
  },
  watch: {
    'type': {
      handler (newVal) {
       this.show()
      },
      immediate: true,
      deep: false
    },
    'value': {
      handler (newVal) {
       this.show()
      },
      immediate: true,
      deep: false
    }
  },
  methods:{
    show () {
      switch(this.type){
        case 'user':
          getUserLabel (this.$http, this.value).then(data=>{
            this.label = data
          })
          break
        case 'role':
          getRoleLabel (this.$http, this.value).then(data=>{
            this.label = data
          })
          break
        case 'company':
          getDepartLabel (this.$http, this.value).then(data=>{
            this.label = data
          })
        case 'depart':
          getDepartLabel (this.$http, this.value).then(data=>{
            this.label = data
          })
          break
        case 'post':
          getPostLabel (this.$http, this.value).then(data=>{
            this.label = data
          })
          break
      }
    }
  }
}
</script>